package com.tiany.kotlin_study

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.tiany.kotlin_study.Class.Fruit
import com.tiany.kotlin_study.MyAdapter.FruitAdapter_recycler
import kotlinx.android.synthetic.main.activity_fourth.*

class FourthActivity : AppCompatActivity() {
    private val fruitList=ArrayList<Fruit>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_fourth)
        //初始化水果数据
        initFruits()
        val layoutManager=LinearLayoutManager(this)
        layoutManager.orientation=LinearLayoutManager.HORIZONTAL
        recyclerView.layoutManager=layoutManager
        val adapter=FruitAdapter_recycler(fruitList)
        recyclerView.adapter=adapter
    }

    private fun initFruits() {
        repeat(10) {//填充十次
            fruitList.add(Fruit("苹果", R.drawable.apple,))
            fruitList.add(Fruit("香蕉", R.drawable.banana,))
            fruitList.add(Fruit("橘子", R.drawable.orange,))
            fruitList.add(Fruit("葡萄", R.drawable.grapes,))
            fruitList.add(Fruit("菠萝", R.drawable.pineapple,))
            fruitList.add(Fruit("香梨", R.drawable.pear,))
        }
    }
}